home comics writing pictures archive about

hangman.java

Language: Java
Last Modified: 2020-06-27 1:58:33 PM UTC
File Size: 1283 bytes
http://www.penguinstew.ca/example/hangman/hangman.java
public class hangman {
public static void main(String[] args) throws Exception{
wordList wList = new wordList();
word alphabet = new word();
word game;
man hMan = new man();
boolean replay = true;
boolean found = false;
char guess;
while(replay) {
replay = false;
game = wList.newWord();
alphabet.reset();
hMan.reset();
found = false;
while(!found) {
hMan.printMan();
game.print();
System.out.println();
alphabet.printNoline();
System.out.println("Type a letter to guess");
guess = (char) System.in.read();
System.in.skip(1024);
if (alphabet.testGuess(guess) && !game.tryGuess(guess)) {
hMan.increase();
}
if (game.test()) {
hMan.printMan();
game.print();
System.out.println();
System.out.println("YOU HAVE WON!");
found = true;
} else if(hMan.death()) {
hMan.printMan();
game.printAll();
System.out.println();
System.out.println("YOU HAVE LOST! BOOO!");
found = true;
}
}
System.out.println();
System.out.println("Do you want to play again?");
guess = (char) System.in.read();
System.in.skip(1024);
if (guess == 'y' || guess == 'Y') {
replay = true;
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54